package fi.helsinki.cs.ohtu10k.view;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;

/**
 * Class implementing the grid panel for week view. 
 * @author Simo Hellsten
 *
 */
@SuppressWarnings("serial")
public class WeekGridPanel extends JPanel{
	
	private ArrayList<Shape> slots;
	private ArrayList<WeekGridLabel> labels;
	private String[] weekdays = {"maanantai", "tiistai", "keskiviikko", "torstai", "perjantai", "lauantai", "sunnuntai"};
	
	public WeekGridPanel(int dayWidth, int hourHeight, int labelWidth, int labelHeight, int hoursPerDay, int firstHour, int offsetX, int offsetY) {
		slots = new ArrayList<Shape>();
		labels = new ArrayList<WeekGridLabel>();
		this.setLayout(null);
		this.setOpaque(false);
		for (int hours=0;hours<hoursPerDay;hours++) {
			slots.add(new Rectangle2D.Float(offsetX, offsetY+labelHeight+hours*hourHeight, labelWidth, hourHeight));
			labels.add(new WeekGridLabel(""+(hours+firstHour)+"-"+(hours+firstHour+1), offsetX+2, offsetY+labelHeight*2-5+hours*hourHeight));
		}
		for (int days=0;days<7;days++) {
            slots.add(new Rectangle2D.Float(offsetX+labelWidth+days*dayWidth, offsetY, dayWidth, labelHeight));
            labels.add(new WeekGridLabel(weekdays[days], offsetX+2+labelWidth+days*dayWidth, offsetY+labelHeight-5));
    		for (int hours=0;hours<hoursPerDay;hours++)
    			slots.add(new Rectangle2D.Float(offsetX+labelWidth+days*dayWidth, offsetY+labelHeight+hours*hourHeight, dayWidth, hourHeight));
    	}
	}
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
   		Graphics2D g2d = (Graphics2D) g;
		for (Shape s : slots) {
			g2d.draw(s);
		}
		for (WeekGridLabel l : labels) {
			g2d.drawString(l.s, l.x, l.y);
		}
	}
}
